package org.example.infrastructure.order.gatewayimpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.example.domain.order.entity.OrderItemEntity;
import org.example.domain.order.gateway.OrderItemGateway;
import org.example.infrastructure.common.base.BaseGatewayImpl;
import org.example.infrastructure.order.convertor.OrderItemConvertor;
import org.example.infrastructure.order.gatewayimpl.database.dataobject.OrderItemDO;
import org.example.infrastructure.order.gatewayimpl.database.mapper.OrderItemMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class OrderItemGatewayImpl extends BaseGatewayImpl<Long, OrderItemEntity, OrderItemDO, OrderItemMapper, OrderItemConvertor> implements OrderItemGateway {

    @Resource
    private OrderItemMapper orderItemMapper;

    @Override
    public List<OrderItemEntity> listByOrderNo(String orderNo) {
        if (StringUtils.isBlank(orderNo)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<OrderItemDO> queryWrapper = Wrappers.lambdaQuery(OrderItemDO.class)
                .eq(OrderItemDO::getOrderNo, orderNo);
        List<OrderItemDO> orderItemDOList = orderItemMapper.selectList(queryWrapper);
        return convertor.toEntityList(orderItemDOList);
    }
}
